package message;

import socket.ChessServer;
import thread.ClientAtServerThread;

/**
 * 登出报文.
 *
 * @author 张紘溢
 */
public class LogoutMessage extends BaseMessage {
    @Override
    public void sendToServer() {
        //循环找出当前登录账号
        for (ClientAtServerThread clientAtServerThread : ChessServer.getInstance().clientAtServerThreadList) {
            if (clientAtServerThread.getClient() == this.sender.getClient()) {
                clientAtServerThread.setUser(null);
                break;
            }
        }
        //更新在线用户列表
        ServerUserListMessage serverUserListMessage = new ServerUserListMessage(ChessServer.getInstance().getUserList());
        ChessServer.getInstance().sendMsgToAll(serverUserListMessage);
    }

    @Override
    public void selfExecute() {

    }
}
